var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var Schema = mongoose.Schema;
/*
 * mongoose.connect('mongodb://user:pass@localhost:port/database', { config: {
 * autoIndex: false } });
 */
mongoose.connect('mongodb://root:123456@localhost:27017/tutorial', { useMongoClient: true});
var childSchema = new Schema({ body: String, date: Date }, { _id: false });
var blogSchema = new Schema({
	  title:  String,
	  author: String,
	  body:   String,
	  comments: [ childSchema ],
	  date: { type: Date, default: Date.now },
	  hidden: Boolean,
	  meta: {
	    votes: Number,
	    favs:  Number
	  }
	},{ collection:'blog',timestamps:true});

//blogSchema.path('title').required(true);

var Blog = mongoose.model('Blog', blogSchema);
var data = {title:'title',author:'jjs1',body:'body',
		comments:[{body:'com1',date:new Date()},{body:'com2',date:new Date()}],
		hidden:'false',
		meta:{
			votes:12,
			favs:10
		}
	};
var doc = new Blog(data);
doc.save()
Blog.count().then(console.log);

//Blog.find().sort({_id:-1}).limit(1).then(console.log)
//console.log(count.mongooseCollection.conn.pass)


//Blog.updateMany({"title" : "title"},{title:'hello'}).then(console.log);








